import api from '../../api/blog'
import helper from '../../utils/helper'
// state
const state = {
  postList: [],
  postInfo: {},
  postView: {}
}

// mutations
const mutations = {
  getPostList(state, item) {
    state.postList = item
  }
}

// actions
const actions = {
  // 获取文章列表
  async getPostList(ctx) {
    const { data } = await api.getPostList()
    ctx.commit('getPostList', data)
    return data
  }
}

// getters
const getters = {
  // 文章处理
  getPostList(state) {
    return state.postList.map(item => {
      // item.content = helper.md.render(item.content)
      item.description = helper.md.render(item.description)
      return item
    })
  },

  // 获取文章详情
  getPostDetail(state, id) {
    return state.postList.filter(item => item.id === id)
  }
}

export default {
  state,
  mutations,
  actions,
  getters
}
